package com.micro.ai.models.entity;

import com.baomidou.mybatisplus.annotation.*;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 微调任务实体类
 * 
 * @author micro-ai
 * @since 0.0.1
 */
@Data
@TableName("fine_tuning_jobs")
@Schema(description = "微调任务信息")
public class FineTuningJob implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 主键ID
     */
    @TableId(value = "id", type = IdType.ASSIGN_ID)
    @Schema(description = "任务ID", example = "job_123456789")
    private String id;

    /**
     * 租户ID
     */
    @Schema(description = "租户ID", example = "tenant_001", required = true)
    private String tenantId;

    /**
     * 任务名称
     */
    @Schema(description = "任务名称", example = "GPT-4中文对话微调", required = true)
    private String jobName;

    /**
     * 基础模型ID
     */
    @Schema(description = "基础模型ID", example = "model_123", required = true)
    private String baseModelId;

    /**
     * 训练数据集ID
     */
    @Schema(description = "训练数据集ID", example = "ds_123", required = true)
    private String datasetId;

    /**
     * 微调后模型名称
     */
    @Schema(description = "微调后模型名称", example = "gpt-4-chinese-dialog")
    private String fineTunedModelName;

    /**
     * 训练参数（JSON）
     */
    @Schema(description = "训练参数（JSON格式）", example = "{\"epochs\":3,\"learningRate\":0.0001}", required = true)
    private String trainingParameters;

    /**
     * 状态
     */
    @Schema(description = "状态", example = "completed", allowableValues = {"pending", "preparing", "training", "evaluating", "completed", "failed", "cancelled"})
    private String status;

    /**
     * 进度百分比
     */
    @Schema(description = "进度百分比（0-100）", example = "85.5")
    private BigDecimal progressPercent;

    /**
     * 当前轮次
     */
    @Schema(description = "当前轮次", example = "2")
    private Integer currentEpoch;

    /**
     * 总轮次
     */
    @Schema(description = "总轮次", example = "3")
    private Integer totalEpochs;

    /**
     * 计算成本
     */
    @Schema(description = "计算成本（美元）", example = "12.50")
    private BigDecimal computeCost;

    /**
     * 训练时长(秒)
     */
    @Schema(description = "训练时长（秒）", example = "3600")
    private Integer trainingDuration;

    /**
     * 训练损失
     */
    @Schema(description = "训练损失", example = "0.0234")
    private BigDecimal trainingLoss;

    /**
     * 评估损失
     */
    @Schema(description = "评估损失", example = "0.0256")
    private BigDecimal evalLoss;

    /**
     * 评估指标（JSON）
     */
    @Schema(description = "评估指标（JSON格式）", example = "{\"accuracy\":0.95,\"f1\":0.93}")
    private String evalMetrics;

    /**
     * 外部平台任务ID
     */
    @Schema(description = "外部平台任务ID", example = "ext_job_123")
    private String externalJobId;

    /**
     * 外部平台模型ID
     */
    @Schema(description = "外部平台模型ID", example = "ext_model_123")
    private String externalModelId;

    /**
     * 错误信息
     */
    @Schema(description = "错误信息", example = "内存不足")
    private String errorMessage;

    /**
     * 训练日志
     */
    @Schema(description = "训练日志", example = "开始训练...")
    private String logs;

    /**
     * 创建人ID
     */
    @Schema(description = "创建人ID", example = "1001", required = true)
    private String createdBy;

    /**
     * 开始时间
     */
    @Schema(description = "开始时间", example = "2025-01-01 00:00:00")
    private LocalDateTime startedAt;

    /**
     * 完成时间
     */
    @Schema(description = "完成时间", example = "2025-01-01 02:00:00")
    private LocalDateTime completedAt;

    /**
     * 创建时间
     */
    @TableField(fill = FieldFill.INSERT)
    @Schema(description = "创建时间", example = "2025-01-01 00:00:00")
    private LocalDateTime createdAt;

    /**
     * 更新时间
     */
    @TableField(fill = FieldFill.INSERT_UPDATE)
    @Schema(description = "更新时间", example = "2025-01-01 00:00:00")
    private LocalDateTime updatedAt;
}
